package com.example.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;

import org.openqa.selenium.Alert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

public abstract class Page {

	public WebDriver driver;
	private boolean acceptNextAlert = true;

	public boolean isOnThisPage() {
		return true;
	}
	
	abstract void tryToOpen();
	
	public WebDriverWait wait_(){
		return new WebDriverWait(driver, 10);
	}
	
	  public String closeAlertAndGetItsText() {
		    try {
		      //Alert alert = driver.switchTo().alert();
		      Alert alert = wait_().until(alertIsPresent());
		      if (acceptNextAlert) {
		        alert.accept();
		      } else {
		        alert.dismiss();
		      }
		      return alert.getText();
		    } finally {
		      acceptNextAlert = true;
		    }
		  }

}
